package com.springstudy.controller;


import com.springstudy.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Tamako
 * @since 2025/1/13 16:07
 */
@Controller
public class ResponseController1 {

    @RequestMapping("/res1")
    public String res1() {
        return "forward:/index.jsp";
    }

    @RequestMapping("/res2")
    public String res2() {
        return "redirect:/index.jsp";
    }

    @RequestMapping("/res3")
    public ModelAndView res3(ModelAndView modelAndView) {
        User user = new User();
        user.setUsername("Tamako");
        user.setAge(25);
        modelAndView.addObject("user", user);
        modelAndView.setViewName("/index.jsp");
        return modelAndView;
    }

    @RequestMapping("/res4")
    @ResponseBody
    public String res4() {
        return "hello Tamako";
    }
}
